package com.stx.servlet.pay;

import com.stx.bean.Pay;
import com.stx.mapper.PayMapper;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.SQLException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.UUID;

/*添加充值信息*/
@WebServlet(urlPatterns = {"/payAdd"})
public class PayAddServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String id= UUID.randomUUID().toString();      //获取用户uuid
        String name = req.getParameter("name");
        String way = req.getParameter("way");
        String number = req.getParameter("number");
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");   //获取当前时间
        String date = sdf.format(new Date());
        Pay pay = new Pay(id,name,way,number,date);
        try {
            Boolean aBoolean = PayMapper.payAdd(pay);
            resp.sendRedirect("/payList");
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doGet(req, resp);
    }

}
